package cn.school.controller.student;

import cn.school.common.api.CommonResult;
import cn.school.student.entity.StudentGuardian;
import cn.school.student.service.StudentGuardianService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: lx
 * @date: 2024/3/22 9:03
 * @description:
 */
@RestController
@Api(tags = "StudentGuardian => 学生监护人管理")
@RequestMapping("/student/guardian")
public class StudentGuardianController {

    @Autowired
    StudentGuardianService guardianService;

    @ApiOperation("添加学生监护人信息")
    @PostMapping("/add")
    public CommonResult addStudentGuardian(@RequestBody List<StudentGuardian> guardianList){
        int num = guardianService.addStudentGuardian(guardianList);
        if(num > 0){
            return CommonResult.success();
        }else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("查询学生监护人列表")
    @GetMapping("/get/{studentId}")
    public CommonResult getStudentGuardianList(@PathVariable("studentId") Long studentId){
        List<StudentGuardian> list = guardianService.getStudentGuardianList(studentId);
        return CommonResult.success(list);
    }
}
